public class Test {
}




import java.util.*;
public class Solution {
    public int postindex;
    public TreeNode buildTree (int[] inorder, int[] postorder) {
        postindex = postorder.length-1;
        return  buildTreechild(inorder,0, inorder.length-1,postorder);
    }

    public TreeNode buildTreechild(int[] inorder,int begin,int end,
                                   int[] postorder){
        if(begin>end){
            return null;
        }
        TreeNode root = new TreeNode(postorder[postindex]);
        int pos = search(inorder,begin,end,postorder[postindex]);
        if(pos==-1){
            return null;
        }
        postindex--;
        root.right = buildTreechild(inorder,pos+1, end,
                postorder);
        root.left  =buildTreechild(inorder,begin,pos-1,
                postorder);
        return root;

    }
    public int search(int[] inorder,int begin,int end,int key){
        for(int i = begin;i<=end;i++){
            if(inorder[i]==key){
                return i;
            }
        }
        return -1;
    }


}








